package com.monitor.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.monitor.entity.ErpClientsMateriel;

/**
 * <p>
 * 采购订单物料表 Mapper 接口
 * </p>
 *
 * @author LX
 * @since 2018-09-09
 */
public interface ErpClientsMaterielMapper extends BaseMapper<ErpClientsMateriel> {
	@Select("SELECT * from erp_clients_materiel cm	where cm.clients_id=#{id}  and cm.materiel_name=#{name}  and cm.materiel_brand=#{brand}  and cm.materiel_specifications=#{specifications}  and cm.materiel_model=#{model}  and cm.materiel_place=#{place}  and cm.materiel_state=#{state}  and cm.materiel_unit=#{unit}  and cm.materielAmount > cm.outAmount")
	public List<ErpClientsMateriel> selectByMateriel(@Param("id")int id,@Param("name")String name,@Param("brand")String brand,@Param("specifications")String specifications,@Param("model")String model,@Param("place")String place,@Param("state")String state,@Param("unit")String unit);

	// AND c.shenpi='已审批'
	@Select("SELECT IFNULL(sum(cm.materiel_amount),0) FROM erp_clients_materiel as cm LEFT JOIN erp_clients as c ON cm.clients_id=c.id WHERE cm.materiel_name=#{name}  and cm.materiel_brand=#{brand}  and cm.materiel_specifications=#{specifications}  and cm.materiel_model=#{model}  and cm.materiel_place=#{place}  and cm.materiel_state=#{state}  and cm.materiel_unit=#{unit} AND c.customer_id=#{custId} AND c.shenpi='已审批'  AND c.come_lib !=0")
	public Integer selectCountMateriel(@Param("custId")int custId,@Param("name")String name,@Param("brand")String brand,@Param("specifications")String specifications,@Param("model")String model,@Param("place")String place,@Param("state")String state,@Param("unit")String unit);
}
